//
//  NewReportViewController.m
//  mendianjieke
//
//  Created by 响当当 on 10/29/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "NewReportViewController.h"
#import "ReportView.h"

@interface NewReportViewController ()
@property (nonatomic, strong)ReportView *reportView;
@property (nonatomic, strong)NSString *nowTimeStr;
@property (nonatomic, strong)NSString *type;
@property (nonatomic, strong)UIView *noCountView;
@property (nonatomic, strong)UILabel *titleLabel;
@end

@implementation NewReportViewController

- (UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [Utilties creatLabelWithFrame:CGRectMake(0,NAVIBAR_HEIGHT,SCREEN_WIDTH,20*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentCenter
                                           textClor:LCHexColor(0xA36A3F)
                                           textFont:11*kUIScaleBasePlus];
        _titleLabel.text = @"全面的运营报告在电脑端数据中台";
        _titleLabel.backgroundColor = LCHexColor(0xFFF1E5);
    }
    return _titleLabel;
}

- (ReportView *)reportView
{
    if (!_reportView)
    {
        _reportView =  [[ReportView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.titleLabel.frame),SCREEN_WIDTH,SCREEN_HEIGHT-NAVIBAR_HEIGHT-20*kUIScaleBasePlus)];
        WeakSelf(self)
        _reportView.changeTypeBlock = ^(NSString *num) {
            [weakSelf getinfo:num];
            weakSelf.type = num;
        };
        
        _reportView.reloadDataBlock = ^(NSString *num) {
            [weakSelf getinfo:num];
            weakSelf.type = num;
        };
    }
    return _reportView;
}

- (UIView *)noCountView
{
    if (!_noCountView)
       {
           _noCountView = [Utilties getNoCountViewWithFrame:CGRectMake(SCREEN_WIDTH/2-132*kUIScaleBasePlus,SCREEN_HEIGHT/2-80*kUIScaleBasePlus,264*kUIScaleBasePlus,264*kUIScaleBasePlus)
                                                      image:@"no_customer"
                                                      title:@"暂时没有服务中的客户哦~\n点击左下方实时按钮，开始接待吧"];
       }
       return _noCountView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setReportNavWithTitle:@"报告"];
    
    self.type = @"1";
    
    [self.upTimeButton addTarget:self action:@selector(upDay) forControlEvents:UIControlEventTouchUpInside];

    [self.nextTimeButton addTarget:self action:@selector(nextDay) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.reportView];
        
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self refrshDay];
    
    [self getinfo:self.type];

    self.viewType = 0;
}

- (void)upDay
{
    self.nowTimeStr = [Utilties getLastday:[Utilties dateFromString:self.nowTimeStr]];
    self.timeLabel.text = self.nowTimeStr;
    [self getinfo:self.type];
}

- (void)nextDay
{
    
    NSString *nowTimeStr = [Utilties getLastday:[Utilties dateFromString:[Utilties getYearAndMonth]]];
    if ([nowTimeStr isEqualToString:self.nowTimeStr])
    {
        DISMISS_SVP(0.5)
        [SVProgressHUD showWithStatus:@"已是最新数据"];
        return;
    }
    else
    {
        self.nowTimeStr = [Utilties getNextday:[Utilties dateFromString:self.nowTimeStr]];
        self.timeLabel.text = self.nowTimeStr;
        [self getinfo:self.type];
    }
}

- (void)getinfo:(NSString *)type
{
    
    [SVProgressHUD showWithStatus:@"加载中"];
    
    NSDictionary *pramaters = @{
                                    @"date" : self.nowTimeStr,
                                    @"type" : type
                                };
    
    
    NSDictionary *Guestpramaters = @{
                                        @"date" : self.nowTimeStr,
                                        @"type" : @"0"
                                    };
    
    WeakSelf(self)
    
    [infoManager getReportListInfo:Guestpramaters sucess:^(id  _Nonnull acceptData) {
        
        NSArray *arr = [NSArray arrayWithArray:acceptData];
        
        [infoManager recordLineChart:pramaters sucess:^(id  _Nonnull acceptData) {
            
            DISMISS_SVP(0.5)

            ReportLineModel *model = [[ReportLineModel alloc] initWithDic:acceptData];
            [weakSelf.reportView getInfo:model tag:type.integerValue guestArr:arr];
            [weakSelf showNewUserGuideIfNeed];
            
        } fail:^(NSError * _Nullable error) {
            
        }];
        
    } fail:^(NSError * _Nullable error) {
        
    }];
    
    
}


///新手引导,聚光灯
-(void)showNewUserGuideIfNeed
{
    
    ///先注释,方便查看效果
    if([NewUserGuide hadShowNewUserGuideForKey:@"stepseven"])
    {
        return;
    }
    
    UIView *onView ;
    onView = [UIApplication sharedApplication].keyWindow;
    
    CGRect cellFrame = CGRectZero;
    if (current_User.isDemoUser.integerValue == 0)
    {
       cellFrame = CGRectMake(0,45*kUIScaleBasePlus+NAVIBAR_HEIGHT,SCREEN_WIDTH,370*kUIScaleBasePlus);
    }
    else
    {
        cellFrame = CGRectMake(0,45*kUIScaleBasePlus+NAVIBAR_HEIGHT,SCREEN_WIDTH,370*kUIScaleBasePlus);
    }
    
    
    UIBezierPath *cellPath = [UIBezierPath bezierPathWithRoundedRect:[self.view convertRect:cellFrame toView:onView] cornerRadius:0];
    UIImage *cellImage = [UIImage imageNamed:@"step_seven"];
    
      
    CGPoint cellPoint = CGPointMake(0,CGRectGetMaxY(cellFrame));
    
    NewUserGuide *view = [[NewUserGuide alloc] init];
    
    [view showOn:onView path:cellPath appendPath:YES image:cellImage imageAt:cellPoint withKey:@"stepseven" afterTap:^{
       
        
    }];
    
}

@end
    
 
